<template>
    <div class="comRate">
        <!-- 头部导航 -->
        <div class="index_top">
            <div class="into_index">首页<i class="el-icon-close"></i></div>
            <div class="current">分佣比例设置<i class="el-icon-close"></i></div>
        </div>
        <div class="content">
            比例
            <el-input v-model="non_standard_order_rate" type="number" placeholder="请输入佣金比例"></el-input>%
            <el-button type="primary" size="medium" @click="editSubmit">保存</el-button>
            <P style="padding:5px 30px;font-size:14px;color:#333;">（比例范围为{{rate_min}}-{{rate_max}}%）</P>
        </div>
    </div>
</template>
<script>
export default {
    data(){
        return{
            non_standard_order_rate:'',
            rate_id:'',
            rate_max:15,
            rate_min:0,
            role:''
        }
    },
    mounted() {
        this.role = localStorage.getItem('role')
        this.getComRateInfo()
    },
    methods: {
        // 获取佣金比例详情
        getComRateInfo(){
            let sid = localStorage.getItem('sid')
            let params = {
                partner_id:sid,
                partner_type:this.role
            }
            this.$http.post('/api/admin/base/Base/getPromotorRate',params).then(res=>{
                console.log(res,'装企佣金比例详情');
                if(res.code==1){
                    this.non_standard_order_rate = res.data.promotor_rate;
                    this.rate_id = res.data.id
                }
            })
        },

        // 保存按钮
        editSubmit(){
          // if(this.non_standard_order_rate*1<this.rate_min*1 || this.non_standard_order_rate*1>this.rate_max*1){
          //       this.$message.warning('比例范围为'+ this.rate_min + '-' + this.rate_max + '%')
          //       // this.getComRateInfo()
          //       return
          //   }
            let r = /^(?:1[0-5]|[0-9])$/;//0-100的正整数  		 
            if(!r.test(this.non_standard_order_rate)){
              this.$message.warning('分佣比例为0-15的正整数');
              return false;
            }
            
            let sid = localStorage.getItem('sid')
            let params = {
                partner_id:sid,
                partner_type:this.role,
                promotor_rate:this.non_standard_order_rate
            }
            this.$http.post('/api/admin/base/Base/setPromotorRate',params).then(res=>{
                console.log(res,'保存结果');
                if(res.code==1){
                    this.$message.success('保存成功')
                    this.getComRateInfo()
                }else{
                    this.$message.warning(res.msg)
                }
            })
        }
    },
}
</script>
<style lang="less">
    .comRate{
        .content{
            background-color: #fff;
            padding: 30px;
            .el-input{
                width: 20%;
            }
        }
    }
</style>

